﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Libreria.SIG.Negocio;
using System.Configuration;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsMobile(Request.UserAgent))
        {
            Response.Redirect(@"~\Mobile.aspx");
        }

    }

    public static bool IsMobile(string userAgent)
    {
        userAgent = userAgent.ToLower();
        return userAgent.Contains("iphone") ||
              userAgent.Contains("ppc") ||
              userAgent.Contains("windows ce") ||
              userAgent.Contains("blackberry") ||
              userAgent.Contains("opera mini") ||
              userAgent.Contains("mobile") ||
              userAgent.Contains("palm") ||
              userAgent.Contains("portable");
    }

    protected void LoginSIG_Authenticate(object sender, AuthenticateEventArgs e)
    {
        Int32 identificador;
        Int32 perfil;

        e.Authenticated = ExternoNegocio.autenticarUsuario(LoginSIG.UserName, LoginSIG.Password, ConfigurationManager.ConnectionStrings["SIG"].ConnectionString, out identificador, out perfil);

        if (e.Authenticated)
        {
            Session[ConfigurationManager.AppSettings["idUsuario"]] = identificador;
            Session[ConfigurationManager.AppSettings["nombreUsuario"]] = LoginSIG.UserName;
            Session[ConfigurationManager.AppSettings["claveUsuario"]] = LoginSIG.Password;
            Session[ConfigurationManager.AppSettings["perfilUsuario"]] = perfil;
            Session[ConfigurationManager.AppSettings["autenticado"]] = e.Authenticated;
        }
    }
}
